var categoryId;
var currentIndex;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    classfilyDataListProgram: [],
    findmask: true
  },

  showDialog: function () {
    this.dialog.showDialog();
  },
  collect: function(event) {
    var index = event.currentTarget.dataset.index;
    currentIndex = index;
    this.cancelCollect("1")
  },
  uncollect: function(event) {
    var index = event.currentTarget.dataset.index;
    currentIndex = index;
    this.cancelCollect("2")
  },


  // 取消收藏
  cancelCollect: function(status) {
    this.setData({
      showmask: true
    })
    var vm = this
    var dataparm;
    dataparm = {
      "programId": vm.data.classfilyDataListProgram[currentIndex].id,
      "status": 2,
      "userId": wx.getStorageSync("userId")
    }
    if (status == "1") {
      getApp().requestLoading(getApp().globalData.https + "programResource/mark",
        "post", dataparm, "执行中..",
        function(res) {
          if (res.code == 0) {
            vm.showDialog()
            vm.getdata()
          }
        });
    } else {
      getApp().requestLoading(getApp().globalData.https + "programResource/delHistoryMark",
        "post", dataparm, "执行中..",
        function(res) {
          if (res.code == 0) {
            vm.getdata()
          }
        });
    }
  },

  /**
   * 跳转到播放详情页面
   */
  todetails: function(e) {
    var season = e.currentTarget.dataset.season;
    var id = e.currentTarget.dataset.id;
    var title = e.currentTarget.dataset.title; //节目标题 

    var flag = e.currentTarget.dataset.flag
    if (flag != "0") {
      wx.showToast({
        title: '该栏目已下架',
      })
      return
    }
    var vm = this
    //热听绑定、有声小说等、、、点击埋点 
    vm.setData({
      userIdss: wx.getStorageSync("userId"), //用户编号
      homeClassifyProgramId: id, //热听榜等。。栏目点击Id记录
      homeClassifyProgramName: title, //热听榜。。等栏目点击Name记录
    })
    wx.navigateTo({
      url: "/pages/day_day_listen/details/details?id=" + id + "&season=" + season,
      success: function() {},
      fail: function() {}
    })
  },

  getdata: function() {
    var vm = this
    var data;
    data = {
      "categoryId": categoryId,
      "userId": wx.getStorageSync("userId")
    }

    getApp().requestLoading(getApp().globalData.https + "programResource/program/conform",
      "get", data, "加载中..",
      function(res) {
        console.log(res);
        wx.stopPullDownRefresh()
        if (res.code == 0) {
          vm.setData({
            classfilyDataListProgram: res.data,
            showloading: false
          })
        } else {
          vm.setData({
            classfilyDataListProgram: [],
            bottomtext: '没找到相似的栏目哦.',
            showloading: false,
          })
        }

      },
      function(res) {
        console.log(res)
      });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.dialog = this.selectComponent("#dialog");
    categoryId = options.categoryId;
    this.getdata()
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    this.getdata();
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})